import Vue from 'vue'
import VueRouter from 'vue-router'
import {Message} from 'element-ui'

Vue.use(VueRouter)
import Mobile from '@/view/Mobile.vue';
	import MobileHome from '@/view/mobile/MobileHome.vue';
	import MobileLogin from '@/view/mobile/MobileLogin.vue'
	import MobileHeader from '@/components/mobile/default/ModileHeader.vue';
	import MobileFooter from '@/components/mobile/default/ModileFooter.vue';
	import MyHome from '@/view/mobile/MyHome.vue'
		import MyOrders from '@/view/mobile/home/MyOrders.vue'
		import MyShopping from '@/view/mobile/home/MyShopping.vue'
		import MyFavorites from '@/view/mobile/home/MyFavorites.vue'
		import Payment from '@/view/mobile/home/Payment.vue'
	import MobileBooksList from '@/view/mobile/MobileBooksList.vue'
	import MobileBookDetail from '@/view/mobile/MobileBookDetail.vue'
	import MobileSearch from '@/view/mobile/MobileSearch.vue'
	
import Pc from '@/view/pc.vue'
	import Home from '@/view/pc/Home.vue'
	import PcHeader from '@/components/pc/default/PCHeader.vue'
	import PcFooter from '@/components/pc/default/PCFooter.vue'
	import AdminLogin from '@/components/admin/AdminLogin.vue'
	import UserEnroll from '@/view/pc/function/UserEnroll.vue'
	import MyCart from '@/view/pc/function/MyCart.vue'
	import AddOrder from '@/view/pc/function/AddOrder.vue'
	import Pay from '@/view/pc/function/Pay.vue'
	import MyOrder from '@/view/pc/function/MyOrder.vue'
	import PcBookDetail from '@/view/pc/function/PcBookDetail.vue'
	import ClassIfy from '@/view/pc/function/ClassIfy.vue'
	import UserMain from '@/view/user/UserMain.vue'
		import UpdatePwd from '@/view/user/UpdatePwd'
		import UpdatePic from '@/view/user/UpdatePic'
		import UpdateAddr from '@/view/user/UpdateAddr'
import Admin from '@/view/pc/Admin.vue'
	import AdmHome from '@/view/pc/AdmHome.vue'
	import AdminHeader from '@/components/admin/default/AdminHeader.vue'
	import AdminFooter from '@/components/admin/default/AdminFooter.vue'
	import AdminNavigation from '@/components/admin/default/AdminNavigation.vue'
	import HotPhoto from '@/components/admin/HotPhoto.vue'
		import editHotPhoto from '@/components/admin/function/editHotPhoto.vue'
	import AddAdm from '@/components/admin/AddAdm.vue'
	import Booklist1 from '@/components/admin/Booklist1.vue'
	import Booklist2 from '@/components/admin/Booklist2.vue'
	import Goos from '@/components/admin/Goos.vue'
		import editGoos from '@/components/admin/function/editGoos.vue'
	import FreezePwd from '@/components/admin/FreezePwd.vue'
	import Orders from '@/components/admin/Orders.vue'
	import UserSetting from '@/view/mobile/user/UserSetting.vue'
		import MyAddr from '@/view/mobile/user/MyAddr.vue'
		import UpdateUser from '@/view/mobile/user/UpdateUser.vue'
		import UpdateUserPwd from '@/view/mobile/user/UpdateUserPwd.vue'

const routes =[
	{
		path : '/',
		// redirect : {name : 'Home'}
		// redirect : '/mobile/home',
		redirect : '/pc/home'
	},
	{
		path : '/adminlogin',
		name : 'AdminLogin',
		component : AdminLogin
	},
	{
		path : '/admin',
		name : 'Admin',
		component : Admin,
		children : [
			{
			path:'admhome',
			name:'AdmHome',
			components : {
				default : AdmHome,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				},
			},
			{
			path:'hotphoto',
			name:'HotPhoto',
			components : {
				default : HotPhoto,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				},
			},
			{
			path:'edithotphoto',
			name:'editHotPhoto',
			components : {
				default : editHotPhoto,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				},
			},
			{
			path:'addadm',
			name:'AddAdm',
			components : {
				default : AddAdm,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'booklist1',
			name:'Booklist1',
			components : {
				default : Booklist1,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'booklist2',
			name:'Booklist2',
			components : {
				default : Booklist2,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'goos',
			name:'Goos',
				components : {
				default :Goos,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'editgoos',
			name:'editGoos',
				components : {
				default :editGoos,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'freezepwd',
			name:'FreezePwd',
			components : {
			default :FreezePwd,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
			{
			path:'orders',
			name:'Orders',
			components : {
				default :Orders,
				admheader : AdminHeader,
				navigation : AdminNavigation,
				admfooter : AdminFooter
				}
			},
		]
	},
	{
		path : '/pc',
		name : 'Pc',
		component : Pc,
		children : [
			{
				path : 'home',
				name : 'Home',
				// 下面使用的是：命名视图的方式，为router-viwe的name属性匹配组件
				components : {
					default : Home,	//渲染到没有name属性的router-viwe上
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'pcbookdetail/:bookid',
				name : 'PcBookDetail',
				components : {
					default : PcBookDetail,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'userenroll',
				name : 'UserEnroll',
				components : {
					default : UserEnroll,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'mycart',
				name : 'MyCart',
				components : {
					default : MyCart,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'myorder',
				name : 'MyOrder',
				components : {
					default : MyOrder,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'addorder',
				name : 'AddOrder',
				components : {
					default : AddOrder,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'pay',
				name : 'Pay',
				components : {
					default : Pay,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : 'classify',
				name : 'ClassIfy',
				components : {
					default : ClassIfy,
					pcheader : PcHeader,
					pcfooter : PcFooter
				}
			},
			{
				path : '/user',
				name : 'UserMain',
				components : {
					default : UserMain,
					pcheader : PcHeader,
					pcfooter : PcFooter
					},
				children : [
					{path:'updatepwd',name:'UpdatePwd',component : UpdatePwd},
					{path:'updatepic',name:'UpdatePic',component : UpdatePic},
					{path:'updateaddr',name:'UpdateAddr',component : UpdateAddr},
				]
			},
		],
	},
	{
		path : '/mobile',
		name : 'Mobile',
		component : Mobile,
		children : [
			{
				path : 'home',
				name : 'MobileHome',
				// 下面使用的是：命名视图的方式，为router-viwe的name属性匹配组件
				components : {
					default : MobileHome,	//渲染到没有name属性的router-viwe上
					header : MobileHeader,
					footer : MobileFooter
				}
			},
			{
				path : 'login',
				name : 'MobileLogin',
				component : MobileLogin,
			},
			{
				path : 'myhome',
				name : 'MyHome',
				components : {
					default : MyHome,
					header : MobileHeader,
					footer : MobileFooter
				}
			},
			{
				path : 'booklist',
				name : 'MobileBooksList',
				components : {
					default : MobileBooksList,
					header : MobileHeader,
					footer : MobileFooter
				}
			},
			{
				path : 'bookdetail/:bookid',
				name : MobileBookDetail,
				component : MobileBookDetail
			},
			{
				path : 'search',
				name : 'MobileSearch',
				component : MobileSearch
			},
			{
				path : 'myorders',
				name : 'MyOrders',
				component : MyOrders
			},
			{
				path : 'myshopping',
				name : 'MyShopping',
				component : MyShopping
			},
			{
				path : 'myfavorites',
				name : 'MyFavorites',
				component : MyFavorites
			},
			{
				path : 'payment',
				name : 'Payment',
				component : Payment
			},
			{
				path : 'myaddr',
				name : 'MyAddr',
				component : MyAddr
			},
			{
				path : 'usersetting',
				name : 'UserSetting',
				component : UserSetting
			},
			{
				path : 'updateuser',
				name : 'UpdateUser',
				component : UpdateUser
			},
			{
				path : 'updateuserpwd',
				name : 'UpdateUserPwd',
				component : UpdateUserPwd
			},
		]
	},
];

const router =new VueRouter({
	routes,
})

// 全局路由守卫
// 常用于实现拦截登录
router.beforeEach((to,from,next)=>{
	// console.log(to,from)
	// 只对访问购物车组件的路由跳转行为进行拦截
	console.log(to.fullPath);
	if(to.fullPath == '/pc/mycart' || to.fullPath == '/pc/myorder'
	   || to.fullPath == '/mobile/myshopping' || to.fullPath == '/mobile/myorders'){
		   let token =window.localStorage.getItem('token')
		   if(token){
			   next()
		   }else{
			   Message.error('您未登录，请先登录！')
		   }
	   }else{
		   next()
	   }
})

export default router;